package demo05_NotSafeCollections;

import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @author kunkun
 * @className Test01_list
 * @Description 用于测试不安全的list类
 * @date 2025/3/5 20:32
 */
public class Test01_list {
    public static void main(String[] args) {
//        List<String> list = new ArrayList<>();
//        List<String> list = new Vector<>(); //1. 使用vector
//        List<String> list = Collections.synchronizedList(new ArrayList<>()); //2. 使用Collections进行转换
        List<String> list = new CopyOnWriteArrayList<>();//3. 使用juc下的类


        for (int i = 0; i < 20; i++) {
            new Thread(() -> {
                list.add(UUID.randomUUID().toString().substring(0, 5));
                System.out.println(list);
            }, "Thread-" + i).start();
        }



    }
}
